﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BridgeController : MonoBehaviour
{
    // Start is called before the first frame update

    public GameObject Point;   // 桥的扭转点
    private float zAngle = 3.0f;
    private float zrotation = -90.0f;
    private float zLocalRotation ;
    public bool isRun = false;
    public GameObject NextBackPoint;     //通过桥后的回溯点如果该回溯点激活的话则桥不会回退
    void Start()
    {
        zLocalRotation = Point.transform.localRotation.z;
    }
    private void OnTriggerEnter2D(Collider2D collision) {
        if (collision.gameObject.CompareTag("Player"))
        {
            isRun = true;
            AudioManager.PlayerOrgan();
            //todo下压动画
        }
    }
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            if (zrotation < 0.0f)
            {
                zrotation += zAngle; 
                Point.transform.Rotate(0, 0, zAngle, Space.Self);
            }
        }
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            //todo上浮动画
        }

    }

    // Update is called once per frame
    void Update()
    {
        if (isRun && Input.GetKeyDown(KeyCode.F)&& !NextBackPoint.GetComponent<BackPoint>().PointActive) {
            isRun = false;
            zrotation = -90.0f;
            Point.transform.rotation = Quaternion.Euler(0.0f, 0.0f, -90.0f);
        } 
    } 
} 
